package com.smart.village.big.screen.domain;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class Point {
    private double x;
    private double y;

    // 浮点数比较精度
    public static final double EPSILON = 1e-6;

    public Point(double x, double y) {
        // 保留6位小数，避免精度问题
        this.x = round(x, 6);
        this.y = round(y, 6);
    }

    public double getX() {
        return x;
    }

    public double getY() {
        return y;
    }

    // 四舍五入处理
    private double round(double value, int places) {
        if (places < 0) throw new IllegalArgumentException();

        BigDecimal bd = BigDecimal.valueOf(value);
        bd = bd.setScale(places, RoundingMode.HALF_UP);
        return bd.doubleValue();
    }

    @Override
    public String toString() {
        return "(" + x + ", " + y + ")";
    }
}
